package com.example.base_kotlin_xml.model.repository

import com.example.base_kotlin_xml.model.source.TestRemoteDataSource
import com.example.base_model.bean.BaseHttpBean
import com.example.base_model.bean.general.DataMergeBean
import com.example.base_model.bean.general.TestRequest
import kotlinx.coroutines.delay
import javax.inject.Inject
import javax.inject.Singleton

/**
 * @Author jiangKunKun
 * @CreateDate 2025/8/5
 * @Description
 * @SpittingGrooves
 */
@Singleton
class TestRepositoryImpl @Inject constructor(
    private val dataSource: TestRemoteDataSource,
) : TestRepository {
    override suspend fun getAisleCode(code: String, str: String, str2: String): BaseHttpBean<DataMergeBean> {
       return getMultipleDataSources(code, str, str2)
    }

    // 添加多数据源组合示例
    suspend fun getMultipleDataSources(code: String, str: String, str3: String): BaseHttpBean<DataMergeBean> {
        delay(100)
//        return supervisorScope {
//            val codeResultDeferred = async {
//                try {
//                    dataSource.getAisleCode(code)
//                } catch (e: Exception) {
//                    // 返回失败的结果而不是抛出异常
//                    BaseHttpBean(-1, "Failed: ${e.message}", null)
//                }
//            }
//            val listResultDeferred = async {
//                try {
//                    dataSource.getBeanList(listOf(
//                        TestRequest(str, str3),
//                        TestRequest(str, str3)
//                    ))
//                } catch (e: Exception) {
//                    // 返回失败的结果而不是抛出异常
//                    BaseHttpBean(-1, "Failed: ${e.message}", emptyList())
//                }
//            }
//
//            val codeResult = codeResultDeferred.await()
//            val listResult = listResultDeferred.await()
//            BaseHttpBean(0,"success", DataMergeBean(
//                codeData = codeResult,
//                listData = listResult
//            )
//            )
//        }
        return BaseHttpBean(0,"success", DataMergeBean(
            codeData = "假设数据",
            listData = listOf(TestRequest(str, str3),TestRequest(str, str3))
        )
        )
    }

    override suspend fun getBeanList(requests: List<TestRequest>): BaseHttpBean<List<TestRequest>> {
        return dataSource.getBeanList(requests)
    }
}
